<template>
  <div class="ballot_coupon white_bg">
    <p class="cp_store_name sm_font">{{coupon.mchtName}}</p>
    <div class="cp_line"></div>
    <div class="cp_content">
      <div class="cp_type_size">
        <coupon-denomination :item="coupon"></coupon-denomination>
      </div>
      <div class="cp_detail">
        <p class="cp_name md_s_font color_gray_02">{{coupon.couponName}}</p>
        <div class="detail color_gray_02">
          <coupon-star :couponComScore="coupon.comScore"></coupon-star>
          <div class="validtime sm_font">
            有效期至: {{coupon.validatyEnd | endTime2}}
          </div>
        </div>
      </div>
    </div>
    <div class="ballot_btn" @click="ballot" v-if="!result">
      <span v-show="!coupon.flag">投票</span>
      <span v-show="coupon.flag">已投票</span>
    </div>
    <div class="ballot_result" v-else>
      <p class="ranking" :class="{'ranking_01 ranking_image_01': coupon.num === 1 || coupon.awardNum === 1, 'ranking_02 ranking_image_02': coupon.num === 2 || coupon.awardNum === 2, 'ranking_03 ranking_image_03': coupon.num === 3 || coupon.awardNum === 3}" v-if="ranking <= 3 && ranking !== 0 ">
        <span class="md_m_font">{{coupon.awardNum || coupon.num}}</span>
      </p>
      <p :class="{ranking_01: coupon.num === 1 || coupon.awardNum === 1, ranking_02: coupon.num === 2 || coupon.awardNum === 2, ranking_03: coupon.num === 3 || coupon.awardNum === 3}" v-if="ranking <= 3 && ranking !== 0 ">{{coupon.count}}票</p>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    coupon: {
      type: Object,
      default: () => ({})
    },
    result: {
      type: Boolean,
      default: false
    },
    ranking: {
      type: Number
    }
  },
  methods: {
    ballot() {
      this.$emit('ballot', this.coupon)
    }
  }
}
</script>

<style lang="scss" scoped>
  .ballot_coupon {
    width: 100%;
    padding: 0.6rem;
    border-radius: 3px;
    position: relative;
    // margin-bottom: 1rem;
  }
  .cp_store_name {
    padding-bottom: 0.4rem;
    color: #333;
    font-weight: bold;
    text-align: left;
  }
  .cp_line {
    width: 88%;
    border-bottom: 1px solid #ccc;
  }
  .cp_content {
    padding-top: 0.4rem;
    overflow: hidden;
    .cp_type_size {
      width: 3.5rem;
      // height: 4.8rem;
      float: left;
      margin-right: 1rem;
    }
    .cp_detail {
      margin-top: 1rem;
      float: left;
      > div, & > p {
        padding-bottom: 0.5rem;
      }
      .cp_name {
        font-weight: bold;
        text-align: left;
      }
      .validtime {
        float: left;
        margin-left: 0.3rem;
      }
    }
  }

  .ballot_btn {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    right: -1.8rem;
    width: 1rem;
    height: 64%;
    text-align: center;
    padding: 0.5rem 1.3rem;
    background-image: url('../../../images/ballot_btn.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;
    color: #fff;
    span {
      position: absolute;
      width: 1rem;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-weight: bold;
    }
  }
  .ballot_result {
    position: absolute;
    top: 0;
    right: 0.2%;
    width: 3rem;
    text-align: center;
  }
  .ranking {
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center top;
    height: 4rem;
    width: 2.4rem;
    text-align: center;
    position: relative;
  }
  .ranking span {
    position: absolute;
    bottom: 0.8rem;
    left: 50%;
    transform: translateX(-40%);
  }
  .ranking_image_01 {
    background-image: url('../../../images/ballot_result_01.png');
    color:#ad7317;
  }
  .ranking_image_02 {
    background-image: url('../../../images/ballot_result_02.png');
    color: #ed6363;
  }
  .ranking_image_03 {
    background-image: url('../../../images/ballot_result_03.png');
    color: #2ebf9e;
  }
  .ranking_01 {
    color:#ad7317;
  }
  .ranking_02 {
    color: #ed6363;
  }
  .ranking_03 {
    color: #2ebf9e;
  }
</style>
